<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%><%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<tiles:insertDefinition name="layout">
	<tiles:putAttribute name="head">
		<style type="text/css">
.singleLine {
	white-space: nowrap;
	width: 8em;
	overflow: hidden;
	text-overflow: ellipsis;
	display: inline-block;
	overflow: hidden;
}

.conflict {
	background: #b94a48;
}
</style>
		<script type="text/javascript">
			$(function() {
				var startDate;
				var endDate;

				var selectCurrentWeek = function() {
					window.setTimeout(function() {
						$('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active')
					}, 1);
				};

				$('.week-picker').datepicker({
					showWeek : true,
					firstDay : 1,
					dateFormat : 'yy-mm-dd',
					showOtherMonths : true,
					selectOtherMonths : true,
					onSelect : function(dateText, inst) {
						var date = $(this).datepicker('getDate');
						// 从周一开始选择
						startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 1);
						endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 7);
						var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;
						$('#startDate').val($.datepicker.formatDate(dateFormat, startDate, inst.settings));
						$('#endDate').val($.datepicker.formatDate(dateFormat, endDate, inst.settings));

						selectCurrentWeek();
					},
					beforeShowDay : function(date) {
						var cssClass = '';
						if (date >= startDate && date <= endDate)
							cssClass = 'ui-datepicker-current-day';
						return [ true, cssClass ];
					},
					onChangeMonthYear : function(year, month, inst) {
						selectCurrentWeek();
					},
					onClose : function() {
						$("form").submit();
					}
				});

				$('.ui-datepicker-calendar tr').live('mousemove', function() {
					$(this).find('td a').addClass('ui-state-hover');
				});
				$('.ui-datepicker-calendar tr').live('mouseleave', function() {
					$(this).find('td a').removeClass('ui-state-hover');
				});

				$(".dialog").frameDialog({
					width : 800,
					height : 500,
					close : function() {
						if (art.dialog.data("success")) {
							location.reload();
						}
					}
				});
			});
		</script>

	</tiles:putAttribute>
	<tiles:putAttribute name="mainBody">
		<form class="form-horizontal">
			<fieldset>
				<legend>教员~周课程交叉表</legend>
				<div class="control-group">
					<label class="control-label">日期选择</label>
					<div class="controls">
						<input type="text" class="input-small week-picker" id="startDate" name="startDate" value='<s:date name="#startDate" format="yyyy-MM-dd"/>' /> ~ <input
							class="input-small week-picker" type="text" id="endDate" name="endDate" value='<s:date name="#endDate" format="yyyy-MM-dd"/>'> 第${week}周
					</div>
				</div>
			</fieldset>
		</form>
		<table class="table table-bordered table-hover table-condensed table-striped">
			<thead>
				<tr>
					<th style="width: 5em">教师</th>
					<th><s:url namespace="/lesson" action="listDailyLesson" id="listDailyLesson">
							<s:param name="startDate" value="getFormateDay(#timePairs[0].startDate)"></s:param>
						</s:url> <a href="${listDailyLesson}">周一</a></th>
					<th><s:url namespace="/lesson" action="listDailyLesson" id="listDailyLesson">
							<s:param name="startDate" value="getFormateDay(#timePairs[1].startDate)"></s:param>
						</s:url> <a href="${listDailyLesson}">周二</a></th>
					<th><s:url namespace="/lesson" action="listDailyLesson" id="listDailyLesson">
							<s:param name="startDate" value="getFormateDay(#timePairs[2].startDate)"></s:param>
						</s:url> <a href="${listDailyLesson}">周三</a></th>
					<th><s:url namespace="/lesson" action="listDailyLesson" id="listDailyLesson">
							<s:param name="startDate" value="getFormateDay(#timePairs[3].startDate)"></s:param>
						</s:url> <a href="${listDailyLesson}">周四</a></th>
					<th><s:url namespace="/lesson" action="listDailyLesson" id="listDailyLesson">
							<s:param name="startDate" value="getFormateDay(#timePairs[4].startDate)"></s:param>
						</s:url> <a href="${listDailyLesson}">周五</a></th>
					<th><s:url namespace="/lesson" action="listDailyLesson" id="listDailyLesson">
							<s:param name="startDate" value="getFormateDay(#timePairs[5].startDate)"></s:param>
						</s:url> <a href="${listDailyLesson}">周六</a></th>
					<th><s:url namespace="/lesson" action="listDailyLesson" id="listDailyLesson">
							<s:param name="startDate" value="getFormateDay(#timePairs[6].startDate)"></s:param>
						</s:url> <a href="${listDailyLesson}">周日</a></th>
				</tr>
			</thead>
			<tbody>
				<s:iterator value="teachers" var="teacher">
					<tr>
						<td><s:url action="listTeacherLesson" namespace="/schedule" id="listTeacherLesson">
								<s:param name="teacherId" value="id"></s:param>
								<s:param name="startDate" value="getFormateDay(#timePairs[0].startDate)"></s:param>
								<s:param name="endDate" value="getFormateDay(#timePairs[6].endDate)"></s:param>
							</s:url> <a href="${listTeacherLesson}">${teacher.name}</a>
							<div class="muted">
								共<strong><s:property value="countTeachings(#teacher, #timePairs[0].startDate,#timePairs[6].endDate )" /> </strong>节课 <br />
								<s:property value="sumTeachings(#teacher, #timePairs[0].startDate,#timePairs[6].endDate )" />
								课时
							</div></td>
						<s:iterator value="#timePairs" var="timePair">
							<td><s:set name="teachings" value="findByTeacherAndDay(#teacher,#timePair)" />
								<dl <s:if test="isInTeachingsConflict(#teachings)">class="conflict"</s:if>>
									<s:iterator value="#teachings" var="teaching" status="status">
										<dt>
											${teaching.timespan}
											<s:if test="lesson.canceled">
												<span class="label">已取消</span>
											</s:if>
										</dt>
										<dd class="singleLine ${teaching.lesson.courseType.cssClass}">
											<s:url action="viewLesson" namespace="/lesson" id="viewLesson">
												<s:param name="id" value="lesson.id"></s:param>
											</s:url>
											<a href="${viewLesson}" class="dialog" title="${teaching.lesson.name}">${teaching.lesson.name}</a>

										</dd>
									</s:iterator>
								</dl></td>
						</s:iterator>
					</tr>
				</s:iterator>
			</tbody>
			<tfoot></tfoot>
		</table>
	</tiles:putAttribute>
</tiles:insertDefinition>